package com.zxm.ex.film.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxm.ex.common.exception.BackendException;
import com.zxm.ex.common.vo.FilmPage;
import com.zxm.ex.common.vo.PageResultVo;
import com.zxm.ex.film.controller.vo.FilmVo;
import com.zxm.ex.film.controller.vo.MoocActorVo;
import com.zxm.ex.film.dao.mapper.MoocActorTMapper;
import com.zxm.ex.film.dao.mapper.MoocFilmTMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FilmServiceImpl implements IFilmService {


    @Autowired
    private MoocActorTMapper moocActorTMapper;
    @Autowired
    private MoocFilmTMapper moocFilmTMapper;

    @Override
    public FilmVo getFilmById(String filmId) throws BackendException {
        FilmVo filmVo = moocFilmTMapper.getFilmById(filmId);
        if(null==filmVo){
            throw new BackendException(404,"没有找到该影片的信息，filmId: "+filmId);
        }
        return filmVo;
    }

    @Override
    public PageResultVo getFilmsList(FilmPage filmPage) throws BackendException {
        Page<MoocActorVo> page = new Page<MoocActorVo>(filmPage.getNowPage(), filmPage.getPageSize());
        IPage<MoocActorVo> ipage = moocActorTMapper.selectMoocActor(page);
        if(ipage.getRecords()==null){
            throw new BackendException(404,"没有影片数据！");
        }
        PageResultVo pageResultVo = new PageResultVo();
        pageResultVo.setNowPage(ipage.getCurrent());
        pageResultVo.setPageSize(ipage.getSize());
        pageResultVo.setTotalSize(ipage.getTotal());
        pageResultVo.setTotalPages(ipage.getPages());
        pageResultVo.setData(ipage.getRecords());
        return pageResultVo;
    }


}
